package com.lx.onbording.vshe.testassignment.core.domain;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Table
@Entity
public class OrderItem implements Serializable {
	private static final long serialVersionUID = 8094499598599108600L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column
	private Long id;
	
	@ManyToOne
	@JoinColumn(name = "product_id")
	private Product product;

	@Column
	private Integer quantity;
	
	@Column(name = "shipping_dep_id")
	private Long shippingDepartmentId;
	
	public OrderItem() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}
	
	
	public Money getPrice() {
		Money price = product.getPrice();
		return new Money(price.getCurrency(), price.getAmount().multiply(
				new BigDecimal(getQuantity())));
	}

	public Integer getAvailableQuantity() {
		return product.getAvalilableQuantity();
	}

	
	public Long getShippingDepartmentId() {
		return shippingDepartmentId;
	}

	public void setShippingDepartmentId(Long shippingDepartmentId) {
		this.shippingDepartmentId = shippingDepartmentId;
	}

	@Override
	public String toString() {
		return "OrderItem [id=" + id + ", product=" + product + ", quantity="
				+ quantity + "]";
	}

}
